﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Cofe.Web
{
    /// <summary>
    /// Represent the relation with the host.
    /// </summary>
    public enum RelationType
    {        
        /// <summary>
        /// Unspecified.
        /// </summary>
        Unknown,
        /// <summary>
        /// Refresh the properties.
        /// </summary>
        Refresh,      
   
        Create,
        /// <summary>
        /// Remove the current entry.
        /// </summary>
        Delete,        
        /// <summary>
        /// Gets more info related to the current entry.
        /// </summary>
        Details,     
        /// <summary>
        /// Get the entry type info of the current entry.
        /// </summary>
        TypeInfo,
        /// <summary>
        /// Get the icon of the current entry.
        /// </summary>
        Icon,
        /// <summary>
        /// Gets the file stream of the current entry for download only.
        /// </summary>
        Download,        
        /// <summary>
        /// Gets the file stream of the current entry for upload only (e.g. new file).
        /// </summary>
        Upload,
        /// <summary>
        /// Gets the file stream of the current entry for upload and download.
        /// </summary>
        Stream,
        /// <summary>
        /// Gets all metadata of the current entry.
        /// </summary>
        Metadata,

        AddTag,

        RemoveTag,

        /// <summary>
        /// Gets a specific property of the current entry.
        /// </summary>
        Property,

        Action,
        /// <summary>
        /// Gets the url for current entry.
        /// </summary>
        Self,

        Parent,
        //For Search
        /// <summary>
        /// Gets the result of the search.
        /// </summary>
        Result,
        /// <summary>
        /// Start a search.
        /// </summary>
        Start,
        /// <summary>
        /// Gets a list of entries
        /// </summary>        
        List,

        /// <summary>
        /// Get the next item (or list).
        /// </summary>
        Next,

        /// <summary>
        /// Get the previous item (or list).
        /// </summary>
        Prev
    }

    /// <summary>
    /// Extends RelationType.
    /// </summary>
    public static class RelationTypeExtension
    {
        /// <summary>
        /// Parse RelationType string to RelationType.
        /// </summary>
        /// <param name="entryString"></param>
        /// <returns></returns>
        public static RelationType Parse(string relString)
        {
            try
            {
                RelationType relType;
                if (Enum.TryParse<RelationType>(relString, out relType))
                    return relType;
                return RelationType.Unknown;
            }
            catch
            {
                return RelationType.Unknown;
            }            
        }
    }


}